# -*- coding = utf-8 -*-
# @Time    : 2025/3/24 下午8:28
# @Author  : yqk
# @File    : 面向对象.py
# @Software: PyCharm

# 1.类
'''
class People:
    def __init__(self, name, age, sex):
        print("创建了一个人")
        self.name = name
        self.age = age
        self.sex = sex
        print("初始化")
    def speak(self):
        print("%s 说: 我 %d 岁。" % (self.name, self.age))
zhangsan = People("张三", 18, "男")
zhangsan.speak()

'''


#继承
'''
class Person:
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex
    def speak(self):
        print("%s 说: 我 %d 岁。" % (self.name, self.age))
class Teacher(Person):
    def teaching(self):
        print("%s is teaching" % self.name)
class Student(Person):
    def study(self):
        print("%s is studying" % self.name)

perry = Teacher("perry", 18, "男")
perry.teaching()

xiaoming = Student("xiaoming", 18, "男")
xiaoming.study()

perry.speak()
xiaoming.speak()
'''
#3.派生
'''
class Person:
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

class Student(Person):
    def __init__(self, name, age,sex,score,major):
        super().__init__(name, age, sex)
        self.score = score
        self.major = major
    def learn(self):
        print(f'{self.name}的分数为{self.score}，专业为{self.major}')

xiaoming = Student('小明',18,'男',100,'python')
xiaoming.learn()
print(xiaoming.age)
'''

# 多态

class Animal:

    def speak(self):
        print("动物会叫")

class Dog(Animal):

    def speak(self):
        print("狗会汪汪叫")
class Cat(Animal):

    def speak(self):
        print("猫会喵喵叫")
class Pig(Animal):

    def speak(self):
        print("猪会哼哼叫")

dog = Dog()
cat = Cat()
pig = Pig()
dog.speak()
cat.speak()
pig.speak()





